const Router = require('koa-router')

const { 
  verifyAuth,
  verifyPermission
} = require('../middlewares/auth.middleware')

const { 
  create,
  detail,
  list,
  update,
  remove,
  addLabels,
  pictureInfo
} = require('../controllers/moment.controller')

const { verifyLabelExists } = require('../middlewares/label.middleware')

const momentRouter = new Router({ prefix: '/moment' })

// 发表动态
momentRouter.post('/', verifyAuth, create)

// 获取某一条动态
momentRouter.get('/:momentId', detail)
// 获取用户动态列表
momentRouter.get('/', list)

// 1.用户必须登录 
// 2.用户是否具备权限去修改或者删除动态内容
//   对于当前项目来讲，不同用户之间是不能互相修改或者删除动态内容的
// 修改动态
momentRouter.patch('/:momentId', verifyAuth, verifyPermission, update)
momentRouter.delete('/:momentId', verifyAuth, verifyPermission, remove)

// 动态添加标签
momentRouter.post('/:momentId/labels', verifyAuth, verifyPermission, verifyLabelExists, addLabels)

// 获取动态配图
momentRouter.get('/images/:filename', pictureInfo)

module.exports = momentRouter
